package models;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import play.db.jpa.GenericModel;
import play.db.jpa.Model;

@Entity
public class Skill extends GenericModel implements Comparable<Skill> {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "SKILL_ID")
	private int skillID;

	@OneToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "SKILL_CATEGORY", referencedColumnName = "SKILL_CATEGORY_ID")
	private SkillCategory category;

	@OneToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "SKILL_SUBCATEGORY", referencedColumnName = "SKILL_SUBCATEGORY_ID")
	private SkillSubCategory subcategory;

	@Column(name = "skill_name")
	private String name;

	public Skill(String name) {
		super();
		this.name = name;
	}

	public Skill() {
		super();
	}

	@Override
	public String toString() {
		return name;
	}

	public int getSkillID() {
		return skillID;
	}

	public void setSkillID(int skillID) {
		this.skillID = skillID;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public SkillCategory getCategory() {
		return category;
	}

	public void setCategory(SkillCategory category) {
		this.category = category;
	}

	public SkillSubCategory getSubcategory() {
		return subcategory;
	}

	public void setSubcategory(SkillSubCategory subcategory) {
		this.subcategory = subcategory;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + skillID;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Skill other = (Skill) obj;
		if (skillID != other.skillID)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	//@Override
	public int compareTo(Skill o) {
		return this.name.compareTo(o.getName());
	}
}
